package com.jxnu.duewang.zmly.zouZhen.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.jxnu.duewang.zmly.BR;
import com.jxnu.duewang.zmly.R;
import com.jxnu.duewang.zmly.zouZhen.model.DataBindingDiscoverEditorRecommend;

import java.util.List;

/**
 * Project Zmly
 * Author Duewang
 * Time 2016/12/8 0008
 */

public class ListViewAdapter extends BaseAdapter {

    private Context mContext;
    private List<DataBindingDiscoverEditorRecommend> mDataBindingDiscoverEditorRecommends;

    public ListViewAdapter(Context context, List<DataBindingDiscoverEditorRecommend> dataBindingDiscoverEditorRecommends) {
        mContext = context;
        mDataBindingDiscoverEditorRecommends = dataBindingDiscoverEditorRecommends;
    }

    @Override
    public int getCount() {
        int ret=0;
        if (mDataBindingDiscoverEditorRecommends != null) {
            ret=mDataBindingDiscoverEditorRecommends.size();
        }
        return ret;
    }

    @Override
    public Object getItem(int position) {
        return mDataBindingDiscoverEditorRecommends.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View ret;
        ViewDataBinding binding;
        if (convertView != null) {
            ret=convertView;
        }else {
            ret= DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.discover_editor_recommend_lauout,parent,false).getRoot();
        }
        binding = DataBindingUtil.bind(ret);
        binding.setVariable(BR.editorRecommend,mDataBindingDiscoverEditorRecommends.get(position));
        return ret;
    }

}
